package org.ting.book.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.ting.book.model.BorrowRecord;

import java.util.List;

@Mapper
public interface BorrowMapper {
    @Insert("insert into borrow_record(user_id, book_id) values(#{userId}, #{bookId})")
    Integer insert(Integer userId, Integer bookId);

    @Select("select * from borrow_record where user_id = #{userId} and is_return = 0")
    List<BorrowRecord> getBorrowByUserId(Integer userId);

    @Select("select * from borrow_record where id = #{id}")
    BorrowRecord getRecordById(Integer id);

    @Update("update borrow_record set is_return = #{isReturn} where id = #{id}")
    Integer updateIsReturn(BorrowRecord borrowRecord);
}
